﻿#pragma once

#include <QObject>
#include <qtcpserver.h>
#include <qtcpsocket.h>

class MainWindowh;
class CommandServer : public QObject
{
	Q_OBJECT

public:
	CommandServer(quint16 port, QObject *parent = nullptr);
	~CommandServer();

	void SetProcessor(MainWindowh* handle);

	Q_INVOKABLE  void start();

	void stop();

signals:
	void serviceStarted(const QString& message);
	void serviceStopped(const QString& message);
	void errorOccurred(const QString& error);
	void commandReceived(const QString& command);
	void commandProcessed(const QString& command, bool success);

private slots:
	void handleNewConnection();

	void processClientData(QTcpSocket* client);
private:
	quint16 m_port;
	QTcpServer* m_server;
	MainWindowh* m_process = nullptr;
};
